package com.xing.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xing.DTO.ConferenceDTO;
import com.xing.DTO.VideoDTO;
import com.xing.Utils.Result;
import com.xing.service.ConferenceService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2024/1/16 16:53
 */
@RestController
@RequestMapping("conference")
@Slf4j
public class ConferenceController {
    @Autowired
    private ConferenceService conferenceService;

    @Operation(summary = "搜索")
    @GetMapping("/page")
    public Result Page(@RequestParam Map<String, Object> params) {
        log.info("Conference.Page=params:{}", params);
        IPage page = conferenceService.Page(params);
        return new Result().ok(page);
    }

    @Operation(summary = "创建会议")
    @PostMapping("create")
    public Result create(@RequestBody ConferenceDTO conferenceDTO) throws Exception {
        String code = conferenceService.create(conferenceDTO);
        return new Result().ok(code);
    }

    //传入流
    @Operation(summary = "传入流")
    @PostMapping("commit")
    public Result commit(@RequestBody ConferenceDTO conferenceDTO) throws Exception {
        String code = conferenceService.commit(conferenceDTO);
        return new Result().ok(code);
    }

    @Operation(summary = "加入房间")
    @PostMapping("into")
    public Result into(@RequestBody ConferenceDTO conferenceDTO) throws Exception {
        Object obj = conferenceService.into(conferenceDTO);
        if (ObjectUtils.isEmpty(obj)) {
            return new Result().err(568);
        }
        return new Result().ok(obj);
    }

    @Operation(summary = "离开会议")
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") String id) {
        conferenceService.Delete(id);
        return new Result().ok();
    }

    @Operation(summary = "展示房间内的所有信息")
    @GetMapping("videoList")
    public Result getVideoList(@Param("roomId") String roomId) {
        List<VideoDTO> list = conferenceService.GetVideoList(roomId);
        return new Result().ok(list);
    }


    @Operation(summary = "删除会议记录")
    @GetMapping("del")
    public Result DelConfernce() {
        return new Result();
    }

}
